package com.example.springboottest.example.workflow;

import java.util.HashMap;
import java.util.Map;

import org.kie.api.KieServices;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;
import org.kie.api.runtime.process.ProcessInstance;


/**
 * 
 * activiti的bpmn2插件地址是   http://activiti.org/designer/update
 * jbpm    的bpmn2插件地址是   http://download.eclipse.org/bpmn2-modeler/updates/neon/1.3.0
 * 
 * 两者只能装一个
 * 
 * 绘制出的bpmn文件可以互用，但个别地方需要调整。例如businessRuleTask节点，需要配置ruleFlowGroup属性
 * jbpm的配置是      tns:ruleFlowGroup="ageGroup"
 * activiti的配置是  ruleFlowGroup="ageGroup"
 * 
 * 
 */
public class ActivitiOrJbpmProcessTest {

	public static final void main(String[] args) {
		try {
			// load up the knowledge base
			KieServices ks = KieServices.Factory.get();
			KieContainer kContainer = ks.getKieClasspathContainer();
			KieSession kSession = kContainer.newKieSession("ksession-process");

			Person person = new Person("张三", 40, 1000);

			kSession.insert(person);

			// start a new process instance
			Map<String, Object> parameters = new HashMap<>();

			kSession.getWorkItemManager().registerWorkItemHandler("Human Task", new TestWorkItemHandler());
			
			//jbpm的工作流
//			ProcessInstance processInstance = kSession.startProcess("test", parameters);
			//activiti的工作流
			ProcessInstance processInstance = kSession.startProcess("activiti-test", parameters);

			System.out.printf("processInstance.id=%s，processInstance.name=%s", processInstance.getId(),
					processInstance.getProcessName());
		} catch (Throwable t) {
			t.printStackTrace();
		}
	}

}
